<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Payment\Mapper;

use App\Payment\Model\PaymentMember;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 支付金额表Mapper类
 */
class PaymentMemberMapper extends AbstractMapper
{
    /**
     * @var PaymentMember
     */
    public $model;

    public function assignModel()
    {
        $this->model = PaymentMember::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 支付方式ID
        if (isset($params['method_id']) && filled($params['method_id'])) {
            $query->where('method_id', '=', $params['method_id']);
        }

        // 钻石数量
        if (isset($params['diamond']) && filled($params['diamond'])) {
            $query->where('diamond', '=', $params['diamond']);
        }

        // 价格(分)
        if (isset($params['money']) && filled($params['money'])) {
            $query->where('money', '=', $params['money']);
        }

        // 苹果内购产品ID
        if (isset($params['ios_product_id']) && filled($params['ios_product_id'])) {
            $query->where('ios_product_id', '=', $params['ios_product_id']);
        }

        // 排序
        if (isset($params['sort']) && filled($params['sort'])) {
            $query->where('sort', '=', $params['sort']);
        }

        // 首充送充
        if (isset($params['recharge_id']) && filled($params['recharge_id'])) {
            $query->where('recharge_id', '=', $params['recharge_id']);
        }

        // 是否首充(1是，2否)
        if (isset($params['is_first']) && filled($params['is_first'])) {
            $query->where('is_first', '=', $params['is_first']);
        }

        // 状态1可用0禁用
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        // 创建人
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}